package javango.http;

import java.io.IOException;
import java.io.Writer;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * Parent class for a response that represents itself as character data,  as opposed to binary data.
 * 
 * @author johns
 *
 */
public abstract class CharacterHttpResponse extends AbstractHttpResponse implements HttpResponse {

	private final static Log log = LogFactory.getLog(CharacterHttpResponse.class);
	
	public abstract void renderToWriter(Writer w) throws HttpException;

	public void render(HttpServletRequest req, HttpServletResponse resp) throws HttpException {
		try {
			updateResponse(resp);
			renderToWriter(resp.getWriter());
		} catch (IOException e) {
			throw new Http500(e);
		}
	}
	
}
